package cs422.group1.projectsquirrel;

import cs422.group1.projectsquirrel.ExtraSurvey.nextQuestionListener;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;


public class ExtraSurvey5 extends Activity
{
	//Instance variables.
	private Button nextButton;
	private RadioGroup radiobutton;
	
	public void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.extrasurveypage5);
		
		nextButton = (Button)findViewById(R.id.nextButton5);
		radiobutton = (RadioGroup)findViewById(R.id.radioGroup1);
        //Attaching a listener for callback on the next button.
        nextButton.setOnClickListener(new nextQuestionListener()); 
        radiobutton.setOnCheckedChangeListener(new radioGroupListener());
        
        if (ObservationDataManager.isEdit())
        {
        	RadioButton btn = null;
        	if (ObservationDataManager.getData().num_squirrel_change.equals("Decreased"))
        		btn =  (RadioButton)findViewById(R.id.radio1);
        	else if (ObservationDataManager.getData().num_squirrel_change.equals("Stayed the same"))
        		btn = (RadioButton)findViewById(R.id.radio2);
        	if (btn != null)
        		btn.toggle();
        }
        else
        {
        	ObservationDataManager.getData().num_squirrel_change = "Increased";
        }
        
        
	}
	
	public class radioGroupListener implements RadioGroup.OnCheckedChangeListener
	{

		public void onCheckedChanged(RadioGroup arg0, int arg1) {
			RadioButton button = (RadioButton)findViewById(arg0.getCheckedRadioButtonId());
			ObservationDataManager.getData().num_squirrel_change = button.getText().toString();
		}
		
	}
	
	//Callback function for the NEXT button.
	public class nextQuestionListener implements OnClickListener
	{
		public void onClick(View view)
		{
			//gatherData();
			nextPage();
		}
	}
		
	
	//Done with this activity, and moving on to the next one.
	private void nextPage()
	{
		Intent intent = new Intent(this.getBaseContext(),ExtraSurvey6.class);
		startActivity(intent);
	}

	
}
